package com.cms.recursoshumanos.ui.beneficios;

import com.cms.recursoshumanos.cache.ListaBeneficiosAdmCache;
import com.cms.recursoshumanos.cache.UserInfoCache;
import com.cms.recursoshumanos.component.base.CustomButtonColored;
import com.cms.recursoshumanos.constant.Constant;
import com.cms.recursoshumanos.container.ForegroundManager;
import com.cms.recursoshumanos.container.TwoColumnFieldManager;
import com.cms.recursoshumanos.handler.BeneficiosAdministrativosScreenHandler;
import com.cms.recursoshumanos.object.BeneficioAdministrativo;
import com.cms.recursoshumanos.ui.RecursosHumanosScreen;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.FieldChangeListener;
import net.rim.device.api.ui.XYEdges;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.component.ObjectChoiceField;
import net.rim.device.api.ui.decor.BorderFactory;

/**
 * A class extending the MainScreen class, which provides default standard
 * behavior for BlackBerry GUI applications.
 */
public final class BeneficiosAdministrativoScreen extends RecursosHumanosScreen
{
    /**
     * Creates a new MyScreen object
     */
	//static Utileria tools = new Utileria();
	private CustomButtonColored boton_envio_solicitud, 
								boton_consult_info;
	private ObjectChoiceField selector_opcion;
	
	public BeneficiosAdministrativosScreenHandler handler;
	
	public static BeneficiosAdministrativoScreen instance = null;
	
	public static BeneficiosAdministrativoScreen getInstance()
	{
		
		if (instance == null)
		{
			return new BeneficiosAdministrativoScreen();
		}
		else
		{
			return instance;
		}
	}
	public BeneficiosAdministrativoScreen() 
	{
		super(NO_VERTICAL_SCROLL | USE_ALL_HEIGHT );
	
		setComponents();
	}
	
	public void setComponents() 
	{
		ForegroundManager foreground = new ForegroundManager();
		
        TwoColumnFieldManager twoColumnManager = new TwoColumnFieldManager( Display.getWidth() / 3, USE_ALL_WIDTH );
        twoColumnManager.setBorder( BorderFactory.createBitmapBorder( new XYEdges( 10, 10, 10, 10 ), Bitmap.getBitmapResource( "border_simple_white.png" ) ) );
        twoColumnManager.setMargin( 10, 10, 10, 10 );
        twoColumnManager.setPadding( 6, 6, 6, 6 );
        
        selector_opcion = new ObjectChoiceField("Beneficio: ",ListaBeneficiosAdmCache.getInstance().getListaObjetoSelector());
		boton_envio_solicitud = new CustomButtonColored("Obtener Solicitud",ButtonField.CONSUME_CLICK, Constant.COLOR_BUTTON_FOCUS); 

		boton_envio_solicitud.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			 
	   			BeneficioAdministrativo beneficio = ListaBeneficiosAdmCache.getInstance().
	   					getListaBeneficio().getBeneficioAtIndex(selector_opcion.getSelectedIndex());
	   			
	   			BeneficiosAdministrativosScreenHandler handler = new BeneficiosAdministrativosScreenHandler();
	   			handler.getPlanillaBeneficiosAdministrativos(UserInfoCache.getInstance().getUsuario().getNombre_Usuario(),
	   					UserInfoCache.getInstance().getUsuario().getPassword(), 
																beneficio);
				
	       	} 
		}); 
        
        boton_consult_info = new CustomButtonColored("Informacion General",ButtonField.CONSUME_CLICK, Constant.COLOR_BUTTON_FOCUS); 

        boton_consult_info.setChangeListener(new FieldChangeListener() 
        {
	   		public void fieldChanged(Field field, int context) 
	       	{ 
	   			
	       	} 
		}); 
        
        twoColumnManager.add(selector_opcion);
        twoColumnManager.add( boton_envio_solicitud );
        twoColumnManager.add( boton_consult_info );
        
        foreground.add( twoColumnManager );
        add( foreground );
			
	}
	
	
}
